package com.cqrcb.cloud.entity.exception;

import com.alibaba.fastjson.JSON;
import lombok.Data;

/**
 * @author ：29520
 * @date ：Created in 2021/4/13 10:28
 * @description：自定义异常
 * @modified By：
 * @version:
 */
@Data
public class CustomException extends RuntimeException{
    private ExceptionMember exceptionMember;

    private boolean isCustom;
    private int code;
    private String exceptionMsg;

    public CustomException(ExceptionMember exceptionMember) {
        this.exceptionMember = exceptionMember;
    }

    public CustomException(String exceptionMsg) {
        this(true,500,exceptionMsg);
    }

    public CustomException(boolean isCustom, int code, String exceptionMsg) {
        this.isCustom = isCustom;
        this.code = code;
        this.exceptionMsg = exceptionMsg;
    }

    @Override
    public String toString(){
        if(isCustom){
            return JSON.toJSONString(this);
        }else{
            return JSON.toJSONString(exceptionMember);
        }
    }

}
